// MouseSensitiveCollection.cpp: implementation of the CMouseSensitiveCollection class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ansiterminal.h"
#include "MouseSensitiveCollection.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMouseSensitiveCollection::CMouseSensitiveCollection(CAnsiScreen *pScreen)
{
	m_pScreen = pScreen;
	
	m_mouseSensitives.Add(&m_pictureUrlMouseSensitive);
	m_mouseSensitives.Add(&m_urlMouseSensitive);
	m_mouseSensitives.Add(&m_nullMouseSensitive);

	m_activeSensitive = &m_nullMouseSensitive;
}

CMouseSensitiveCollection::~CMouseSensitiveCollection()
{

}

IMouseSensitive* CMouseSensitiveCollection::GetActiveSensitive()
{
	return m_activeSensitive;
}

void CMouseSensitiveCollection::UpdateActiveSensitive(CPoint ptCursorCell)
{
	CSize sizeScr = m_pScreen->GetSize();
	if(ptCursorCell.x < 0 || ptCursorCell.y < 0 || ptCursorCell.x > sizeScr.cx - 1 || ptCursorCell.y > sizeScr.cy - 1)
	{
		m_activeSensitive = &m_nullMouseSensitive;
		return;
	}
	int count = m_mouseSensitives.GetSize();
	for(int n = 0; n < count; n++)
	{
		if(m_mouseSensitives[n]->CheckSensitive(m_pScreen, ptCursorCell, 0))
		{
			if(m_activeSensitive != m_mouseSensitives[n])
			{
				m_activeSensitive->Deactivate();
				m_activeSensitive = m_mouseSensitives[n];
				m_activeSensitive->Activate();
			}
			return;
		}
	}
}

void CMouseSensitiveCollection::SetNullMouseSensitive()
{
	if(m_activeSensitive != &m_nullMouseSensitive)
	{
		m_activeSensitive->Deactivate();
		m_activeSensitive = &m_nullMouseSensitive;
		m_nullMouseSensitive.Activate();
	}
}